<html>
 <head>
  <meta charset="UTF-8">
 </head>
 <body>
  <h1 data-lake-id="dVWYW" id="dVWYW"><span data-lake-id="ud44f94ce" id="ud44f94ce">典型回答</span></h1>
  <p data-lake-id="u89c94a30" id="u89c94a30"><br></p>
  <p data-lake-id="uad849d37" id="uad849d37"><span data-lake-id="uc347a09f" id="uc347a09f">JVM的启动参数有很多，但是我们平常能用上的并不是特别多，这里介绍几个我们常用的：</span></p>
  <p data-lake-id="u083ac5ae" id="u083ac5ae"><br></p>
  <ol list="u72f4a485">
   <li fid="u4fe054fb" data-lake-id="u64df64fb" id="u64df64fb"><strong><span data-lake-id="u24d6bcf6" id="u24d6bcf6">堆设置</span></strong><span data-lake-id="u90ddd0d8" id="u90ddd0d8">：</span></li>
  </ol>
  <ul list="u469b989c" data-lake-indent="1">
   <li fid="u78603517" data-lake-id="u4b8c6314" id="u4b8c6314"><span data-lake-id="u1d755676" id="u1d755676">-Xms</span><span data-lake-id="uce991e58" id="uce991e58">：设置堆的初始大小。</span></li>
   <li fid="u78603517" data-lake-id="u28604f67" id="u28604f67"><span data-lake-id="u7f973638" id="u7f973638">-Xmx</span><span data-lake-id="u96260c0e" id="u96260c0e">：设置堆的最大大小。</span></li>
  </ul>
  <ol list="u72f4a485" start="2">
   <li fid="u4fe054fb" data-lake-id="ua5782a48" id="ua5782a48"><strong><span data-lake-id="u58ceb331" id="u58ceb331">栈设置</span></strong><span data-lake-id="uaf5a084f" id="uaf5a084f">：</span></li>
  </ol>
  <ul list="u83b9eca1" data-lake-indent="1">
   <li fid="u699ecb5b" data-lake-id="ud52bf245" id="ud52bf245"><span data-lake-id="u13c568f7" id="u13c568f7">-Xss</span><span data-lake-id="uf7597d84" id="uf7597d84">：设置每个线程的栈大小。</span></li>
  </ul>
  <ol list="u72f4a485" start="3">
   <li fid="u4fe054fb" data-lake-id="uf6de050c" id="uf6de050c"><strong><span data-lake-id="uf40c1286" id="uf40c1286">垃圾回收器设置</span></strong><span data-lake-id="ub7ef651b" id="ub7ef651b">：</span></li>
  </ol>
  <ul list="u27bdac41" data-lake-indent="1">
   <li fid="u50b720ba" data-lake-id="uee880957" id="uee880957"><span data-lake-id="ufdb7d7c2" id="ufdb7d7c2">-XX:+UseG1GC</span><span data-lake-id="ubead65b9" id="ubead65b9">：使用 G1 垃圾回收器。</span></li>
   <li fid="u50b720ba" data-lake-id="u591703f2" id="u591703f2"><span data-lake-id="ub07a9aef" id="ub07a9aef">-XX:+UseParallelGC</span><span data-lake-id="u4134c20b" id="u4134c20b">：使用并行垃圾回收器。</span></li>
  </ul>
  <ol list="u72f4a485" start="4">
   <li fid="u4fe054fb" data-lake-id="u7af1b14e" id="u7af1b14e"><strong><span data-lake-id="u5da04584" id="u5da04584">性能调优</span></strong><span data-lake-id="u445ccb5d" id="u445ccb5d">：</span></li>
  </ol>
  <ul list="u81f3ab04" data-lake-indent="1">
   <li fid="uccf30eb4" data-lake-id="u0e1ca41f" id="u0e1ca41f"><span data-lake-id="u96032894" id="u96032894">-XX:PermSize</span><span data-lake-id="u4247ff18" id="u4247ff18"> 和 </span><span data-lake-id="uc26e571c" id="uc26e571c">-XX:MaxPermSize</span><span data-lake-id="u8b4c159b" id="u8b4c159b">：在 Java 8 之前设置永久代的初始大小和最大大小。</span></li>
   <li fid="uccf30eb4" data-lake-id="uf2f96bd4" id="uf2f96bd4"><span data-lake-id="ue234ca44" id="ue234ca44">-XX:MetaspaceSize</span><span data-lake-id="u39ca7739" id="u39ca7739"> 和 </span><span data-lake-id="u2af47a37" id="u2af47a37">-XX:MaxMetaspaceSize</span><span data-lake-id="u63937416" id="u63937416">：在 Java 8 及以上版本设置 Metaspace 的初始大小和最大大小。</span></li>
   <li fid="uccf30eb4" data-lake-id="ub335d63d" id="ub335d63d"><span data-lake-id="u89a9e4c4" id="u89a9e4c4">-XX:+PrintGCDetails</span><span data-lake-id="uef473f7b" id="uef473f7b">：打印垃圾回收的详细信息。</span></li>
  </ul>
  <ol list="u72f4a485" start="5">
   <li fid="u4fe054fb" data-lake-id="ua6d7f14f" id="ua6d7f14f"><strong><span data-lake-id="u8c533ed6" id="u8c533ed6">调试和分析</span></strong><span data-lake-id="u91ee924f" id="u91ee924f">：</span></li>
  </ol>
  <ul list="u62774373" data-lake-indent="1">
   <li fid="u449a9972" data-lake-id="u17085ccf" id="u17085ccf"><span data-lake-id="ubf757947" id="ubf757947">-verbose:gc</span><span data-lake-id="uce1b1ccf" id="uce1b1ccf">：输出垃圾回收的详细信息。</span></li>
   <li fid="u449a9972" data-lake-id="u29899bbd" id="u29899bbd"><span data-lake-id="uea9b229e" id="uea9b229e">-XX:+HeapDumpOnOutOfMemoryError：在内存溢出时生成堆转储。</span></li>
  </ul>
  <p data-lake-id="ud11540c2" id="ud11540c2"><span data-lake-id="uc67840be" id="uc67840be">​</span><br></p>
  <h1 data-lake-id="eGukG" id="eGukG"><span data-lake-id="u132646b5" id="u132646b5">扩展知识</span></h1>
  <p data-lake-id="u2e4c08ba" id="u2e4c08ba"><br></p>
  <h2 data-lake-id="lsJbt" id="lsJbt"><span data-lake-id="u589786f7" id="u589786f7">如何使用</span></h2>
  <p data-lake-id="ua4466673" id="ua4466673"><br></p>
  <p data-lake-id="u98e4213e" id="u98e4213e"><span data-lake-id="u83d521eb" id="u83d521eb">要使用这些 JVM 启动参数，你需要在启动 Java 应用程序时在命令行中指定它们。</span></p>
  <p data-lake-id="u9b395054" id="u9b395054"><span data-lake-id="uff206eaf" id="uff206eaf">​</span><br></p>
  <p data-lake-id="ub599d442" id="ub599d442"><span data-lake-id="u09e3717a" id="u09e3717a">例如，如果你想设置最大堆大小为 512MB 并启用 G1 垃圾回收器，你可以这样启动你的 Java 应用程序：</span></p>
  <p data-lake-id="uc9124764" id="uc9124764"><span data-lake-id="ud2eee672" id="ud2eee672">​</span><br></p>
  <pre lang="java"><code>
java -Xmx512m -XX:+UseG1GC -jar your-application.jar
</code></pre>
  <p data-lake-id="u91bc377b" id="u91bc377b"><br></p>
  <p data-lake-id="u694d2e5d" id="u694d2e5d"><br></p>
  <p data-lake-id="u8b908c4a" id="u8b908c4a"><span data-lake-id="ud3f3a98b" id="ud3f3a98b">另外，如果是在IDEA中，需要再run配置中增加上对应的参数，如：</span></p>
  <p data-lake-id="u6b65132a" id="u6b65132a"><span data-lake-id="u34a736a0" id="u34a736a0">​</span><br></p>
  <p data-lake-id="u745d9a7a" id="u745d9a7a"><img src="https://cdn.nlark.com/yuque/0/2023/png/5378072/1704001546418-690df6e2-978d-47c8-8be3-190e26272bb0.png?x-oss-process=image%2Fwatermark%2Ctype_d3F5LW1pY3JvaGVp%2Csize_31%2Ctext_SmF2YSA4IEd1IFA%3D%2Ccolor_FFFFFF%2Cshadow_50%2Ct_80%2Cg_se%2Cx_10%2Cy_10"></p>
  <p data-lake-id="u9f695f13" id="u9f695f13" style="text-align: center"><span data-lake-id="u76b75b36" id="u76b75b36">（图片来源于网络）</span></p>
 </body>
</html>